// 响应状态码枚举
const ResponseCode = {
  SUCCESS: 200,        // 成功
  BAD_REQUEST: 400,    // 客户端错误
  UNAUTHORIZED: 401,   // 未授权
  FORBIDDEN: 403,      // 禁止访问
  NOT_FOUND: 404,      // 资源不存在
  SERVER_ERROR: 500,   // 服务器错误
  CREATED: 201         // 创建成功
};

// 错误消息常量
const ErrorMessage = {
  // 通用错误
  ID_REQUIRED: 'ID不能为空',
  IDS_REQUIRED: '请提供需要删除的ID数组',
  PARAM_INCOMPLETE: '参数不完整',
  UPDATE_TIME_ERROR: '更新时间参数错误',
  DATABASE_ERROR: '数据库操作失败',
  SERVICE_ERROR:'服务错误',
  // 壁纸分类相关
  CLASSIFY_NOT_FOUND: '分类不存在',
  CLASSIFY_NAME_REQUIRED: '分类名称不能为空'
};

/**
 * 统一响应格式类
 */
class ApiResponse {
  constructor(code, msg, data = null) {
    this.code = code
    this.msg = msg
    this.data = data
  }

  static success(data = null, msg = '操作成功') {
    return new ApiResponse(ResponseCode.SUCCESS, msg, data)
  }

  static created(data = null, msg = '创建成功') {
    return new ApiResponse(ResponseCode.CREATED, msg, data)
  }

  static badRequest(msg = '请求参数错误') {
    return new ApiResponse(ResponseCode.BAD_REQUEST, msg)
  }

  static notFound(msg = '资源不存在') {
    return new ApiResponse(ResponseCode.NOT_FOUND, msg)
  }

  static serverError(msg = '服务器内部错误') {
    return new ApiResponse(ResponseCode.SERVER_ERROR, msg)
  }

  static custom(code, msg, data = null) {
    return new ApiResponse(code, msg, data)
  }
}

// 挂载枚举到类上
ApiResponse.ResponseCode = ResponseCode;
ApiResponse.ErrorMessage = ErrorMessage;

module.exports = ApiResponse;